package com.fangcun.controller.api.old;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fangcun.bean.api.goods.request.GoodsSearchRequest;
import com.fangcun.bean.sys.PageBean;
import com.fangcun.bean.sys.ResponseMsg;
import com.fangcun.common.canstant.ErrCode;
import com.fangcun.common.exception.ProException;
import com.fangcun.common.util.PublicMethod;
import com.fangcun.common.util.apiversion.ApiVersion;
import com.fangcun.common.util.base.BaseController;
import com.fangcun.service.api.GoodsApiService;

/**
 * @作者： 陳曉鬆 @时间： 2020年7月15日 - 上午11:22:40 @description：->
 */
@RestController
@RequestMapping("/api/{version}/goods")
public class GoodsApiController extends BaseController {

	private static Logger LOG = LoggerFactory.getLogger(GoodsApiController.class);

	@Resource(name = "goodsApiService")
	private GoodsApiService goodsApiService;
	
	@ApiVersion(1.0)
	@RequestMapping(value = "/list")
	private ResponseMsg list(@RequestBody PageBean<GoodsSearchRequest> request) throws ProException {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(goodsApiService.list(request));
		} catch (ProException e) {
			LOG.error("-商品-列表出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-商品-列表异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping(value = "/detail")
	private ResponseMsg detail(Long priceId) throws ProException {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			Long userId = null;
			try {
				userId = getApiUserId();
			} catch (Exception e) {
			}
			msg.setData(goodsApiService.detail(priceId, userId));
		} catch (ProException e) {
			LOG.error("-商品-详情出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-商品-详情异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

}
